/**
 * 
 */
package cz.cuni.mff.abacs.burglar.visual.multithreading;

import java.util.List;

import aStarLibrary.AStar;
import aStarLibrary.Node;
import cz.cuni.mff.abacs.burglar.logics.ExecutingMap;
import cz.cuni.mff.abacs.burglar.logics.GameMap;
import cz.cuni.mff.abacs.burglar.logics.objects.positions.Position;

/**
 * @author abacs
 *
 */
public class PathfindingThread extends Thread {
	
	/**  */
	private ExecutingMap _map;
	/**  */
	private Node _from;
	/**  */
	private Node _to;
	/**  */
	private PathfinderListener _listener;
	
	
	// -------------------------------------------------------------------------
	// constructors:
	
	/**
	 * 
	 * 
	 * @param map
	 * @param from
	 * @param to
	 * @param handler
	 */
	public PathfindingThread(
			GameMap map,
			Node from,
			Node to,
			PathfinderListener handler
	) {
		super();
		this._map = (ExecutingMap)map;
		this._from = from;
		this._to = to;
		this._listener = handler;
	}
	
	
	// -------------------------------------------------------------------------
	
	
	/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void run() {
		
		AStar aStar = new AStar();
		
		aStar.nodes.addAll(this._map.getNodes());
		
		List<Node> nodes = aStar.getPath(this._from, this._to);
		List<Position> positions = this._map.nodesToPositions(nodes);
		
		this._listener.pathfindingFinished(positions);
	}
	
	
}
